package cn.enjoy.design.behavior.strategy.springInitializingBeanPlus.config;

import cn.enjoy.design.behavior.strategy.springInitializingBeanPlus.HandlerFactory;
import cn.enjoy.design.behavior.strategy.springInitializingBeanPlus.service.ProductCacheManager;
import cn.enjoy.design.behavior.strategy.springInitializingBeanPlus.service.SeckillOrderManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**

 * @author K
 * @date 2022-11-21 21:31
 */
@Configuration
public class StrategyConfig {

    /**
     * 使用@Bean 注入HandlerFactory，使之受到Spring容器的管理
     * 并且HandlerFactory实现了InitializingBean接口，调用getBeansOfType获取到所有实现类
     * 再存放到HandlerFactory的STRATEGY_MAP属性中
     * 之后只需要注入对应的Factory，即可使用策略模式
     */
    @Bean
    public HandlerFactory<Integer, ProductCacheManager> productCacheFactory(){
        return new HandlerFactory<>(ProductCacheManager.class);
    }

    @Bean
    public HandlerFactory<String, SeckillOrderManager> seckillOrderFactory(){
        return new HandlerFactory<>(SeckillOrderManager.class);
    }

}
